'''
Created on Jul 14, 2012

@author: catapult
'''

import pygame
import move
import pokemon

class Button(pygame.sprite.Sprite):
    
    def __init__(self, dispMode):
        self.dispMode = dispMode
        pygame.sprite.Sprite.__init__(self)
        
class AttackChoiceButton(Button):
    
    def __init__(self):
        Button.__init__(self, 1)
        self.image = pygame.image.load("../images/buttons/blankbutton.png").convert()
        self.rect = self.image.get_rect()
        self.image.set_colorkey((255, 255, 255))
        self.font = pygame.font.SysFont("Arial", 16, False, False)
        self.text = self.font.render("Attack", False, (255, 255, 254))
        self.image.blit(self.text, [self.image.get_size()[0] / 2 - self.text.get_size()[0]  / 2, self.image.get_size()[1] / 2 - self.text.get_size()[1] / 2])

class PokeChoiceButton(Button):
    
    def __init__(self):
        Button.__init__(self, 2)
        self.image = pygame.image.load("../images/buttons/blankbutton.png").convert()
        self.rect = self.image.get_rect()
        self.image.set_colorkey((255, 255, 255))
        self.font = pygame.font.SysFont("Arial", 16, False, False)
        self.text = self.font.render("Pokemon", False, (255, 255, 254))
        self.image.blit(self.text, [self.image.get_size()[0] / 2 - self.text.get_size()[0] / 2, self.image.get_size()[1] / 2 - self.text.get_size()[1] / 2])

class ItemChoiceButton(Button):
    
    def __init__(self):
        Button.__init__(self, 3)
        self.image = pygame.image.load("../images/buttons/blankbutton.png").convert()
        self.rect = self.image.get_rect()
        self.image.set_colorkey((255, 255, 255))
        self.font = pygame.font.SysFont("Arial", 16, False, False)
        self.text = self.font.render("Bag", False, (255, 255, 254))
        self.image.blit(self.text, [self.image.get_size()[0] / 2 - self.text.get_size()[0] / 2, self.image.get_size()[1] / 2 - self.text.get_size()[1] / 2])

class FleeChoiceButton(Button):
    
    def __init__(self):
        Button.__init__(self, 4)
        self.image = pygame.image.load("../images/buttons/blankbutton.png").convert()
        self.rect = self.image.get_rect()
        self.image.set_colorkey((255, 255, 255))
        self.font = pygame.font.SysFont("Arial", 16, False, False)
        self.text = self.font.render("Flee", False, (255, 255, 254))
        self.image.blit(self.text, [self.image.get_size()[0] / 2 - self.text.get_size()[0] / 2, self.image.get_size()[1] / 2 - self.text.get_size()[1] / 2])
        
class AttackButton(Button):
    
    def __init__(self, moves):
        Button.__init__(self, 5)
        if(type(moves) == move.Move):
            self.move = moves
            dispName = self.move.name
            ppC = int(self.move.pp[0])
            ppT = int(self.move.pp[1])
            type1 = self.move.type
            typeList = ["", "normal", "fight", "flying", "poison", "ground", "rock", "bug", "ghost", "steel", "fire", "water", "grass", "electr", "psychc", "ice", "dragon", "dark"]
    #        if(type == 1):
    #            type = "normal"
    #        elif(type == 2):
    #            type = "fight"
    #        elif(type == 3):
    #            type = "flying"
    #        elif(type == 4):
    #            type = "poison"
    #        elif(type == 5):
    #            type = "ground"
    #        elif(type == 6):
    #            type = "rock"
    #        elif(type == 7):
    #            type = "bug"
    #        elif(type == 8):
    #            type = "ghost"
    #        elif(type == 9):
    #            type = "steel"
    #        elif(type == 10):
    #            type = "fire"
    #        elif(type == 11):
    #            type = "water"
    #        elif(type == 12):
    #            type = "grass"
    #        elif(type == 13):
    #            type = "electr"
    #        elif(type == 14):
    #            type = "psychc"
            self.image = pygame.image.load("../images/buttons/" + typeList[type1] + "button.png").convert()
            self.rect = self.image.get_rect()
            self.image.set_colorkey((255, 255, 255))
            self.font = pygame.font.SysFont("Arial", 14, True, False)
            moveNameB = self.font.render(dispName, False, (113, 139, 112))
            self.image.blit(moveNameB, [self.image.get_size()[0] / 2 - moveNameB.get_size()[0] / 2 + 1, 12 + 1])
            moveName = self.font.render(dispName, False, (255, 255, 254))
            self.image.blit(moveName, [self.image.get_size()[0] / 2 - moveName.get_size()[0] / 2, 12])
            self.font = pygame.font.SysFont("Arial", 13, False, False)
            if( ppC / ppT <= .5 and ppC / ppT > .25):
                pp11 = self.font.render(str(ppC), False, (215, 172, 0))
                pp21 = self.font.render(str(ppT), False, (215, 172, 0))
            elif(ppC / ppT > .5):
                pp11 = self.font.render(str(ppC), False, (0, 0, 0))
                pp21 = self.font.render(str(ppT), False, (0, 0, 0))
            elif( ppC / ppT <= .25 and ppC > 0):
                pp11 = self.font.render(str(ppC), False, (231, 96, 14))
                pp21 = self.font.render(str(ppT), False, (231, 96, 14))
            else:
                pp11 = self.font.render(str(ppC), False, (190, 40, 33))
                pp21 = self.font.render(str(ppT), False, (190, 40, 33))
            pp12 = self.font.render(str(ppC), False, (113, 139, 112))
            self.image.blit(pp12, [77 - pp12.get_size()[0] / 2 + 1, 27 + 1])
            self.image.blit(pp11, [77 - pp11.get_size()[0] / 2, 27])
            pp22 = self.font.render(str(ppT), False, (113, 139, 112))
            self.image.blit(pp22, [99 - pp22.get_size()[0] / 2 + 1, 27 + 1])
            self.image.blit(pp21, [99 - pp21.get_size()[0] / 2, 27])
        else:
            self.image = pygame.image.load("../images/buttons/mysterybutton.png")
            self.rect = self.image.get_rect()
            self.image.set_colorkey((255, 255, 255))
        
class BackButton(Button):
    def __init__(self):
        Button.__init__(self, 6)
        self.image = pygame.image.load("../images/buttons/blankbutton.png").convert()
        self.rect = self.image.get_rect()
        self.image.set_colorkey((255, 255, 255))
        self.font = pygame.font.SysFont("Arial", 16, False, False)
        self.text = self.font.render("Back", False, (255, 255, 254))
        self.image.blit(self.text, [self.image.get_size()[0] / 2 - self.text.get_size()[0] / 2, self.image.get_size()[1] / 2 - self.text.get_size()[1] / 2])      

class PokeButton(Button):
    
    def __init__(self, poke):
        Button.__init__(self, 7)
        self.poke = poke
        self.image = pygame.image.load("../images/buttons/blankbutton.png").convert()
        self.rect = self.image.get_rect()
        self.image.set_colorkey((255, 255, 255))
        self.font = pygame.font.SysFont("Arial", 16, False, False)
        if(type(self.poke) == pokemon.Pokemon):
           self.text = self.font.render(self.poke.name, False, (255, 255, 254))
        elif(type(self.poke) == type("Hi")):
            self.text = self.font.render(self.poke, False, (255, 255, 254))
        self.image.blit(self.text, [self.image.get_size()[0] / 2 - self.text.get_size()[0] / 2, self.image.get_size()[1] / 2 - self.text.get_size()[1] / 2])      

class SwitchButton(Button):

        def __init__(self):
            Button.__init__(self, 8)
            self.image = pygame.image.load("../images/buttons/blankbutton.png").convert()
            self.rect = self.image.get_rect()
            self.image.set_colorkey((255, 255, 255))
            self.font = pygame.font.SysFont("Arial", 16, False, False)
            self.text = self.font.render("Switch", False, (255, 255, 254))
            self.image.blit(self.text, [self.image.get_size()[0] / 2 - self.text.get_size()[0] / 2, self.image.get_size()[1] / 2 - self.text.get_size()[1] / 2]) 

class SearchButton(Button):

        def __init__(self):
            Button.__init__(self, 9)
            self.image = pygame.image.load("../images/buttons/blankbutton.png").convert()
            self.rect = self.image.get_rect()
            self.image.set_colorkey((255, 255, 255))
            self.font = pygame.font.SysFont("Arial", 16, False, False)
            self.text = self.font.render("Search", False, (255, 255, 254))
            self.image.blit(self.text, [self.image.get_size()[0] / 2 - self.text.get_size()[0] / 2, self.image.get_size()[1] / 2 - self.text.get_size()[1] / 2]) 
            
class TextButton(Button):

        def __init__(self, text):
            Button.__init__(self, 10)
            self.image = pygame.image.load("../images/buttons/textButton.png").convert()
            self.rect = self.image.get_rect()
            self.font = pygame.font.SysFont("Arial", 16, False, False)
            self.text = self.font.render(text, False, (0, 0, 0))
            self.image.blit(self.text, [self.image.get_size()[0] / 2 - self.text.get_size()[0] / 2, self.image.get_size()[1] / 2 - self.text.get_size()[1] / 2]) 
            
class ArrowButton(Button):

        def __init__(self, r=True):
            Button.__init__(self, 11)
            if(r == True):
                self.image = pygame.image.load("../images/moreStuff/arrow.png").convert()
            else:
                self.image = pygame.image.load("../images/moreStuff/arrow2.png").convert()
            self.rect = self.image.get_rect()